package day11.Object;

/**
 * @Auther:小陈的Java
 */
public class CloneDemo1 {
    public static void main(String[] args) throws Exception{
        User user = new User();
        user.setId(1);
        user.setName("张三");
        user.setAge(19);
        User user2 = (User) user.clone();
        System.out.println(user2);
        System.out.println(user == user2);
    }
}
class User extends Object implements Cloneable{
    private int id;
    private String name;
    private int age;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
